package com.woniuxy.Dynamic.cglib;

import com.woniuxy.Dynamic.aspect.QieMianLei;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

public class GongChang {
    public Object jiaGong(Object targetClass){
        Object shangpin = Enhancer.create(targetClass.getClass(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                QieMianLei qiemian = new QieMianLei();
                qiemian.before();
                Object invoke = method.invoke(targetClass, args);
                qiemian.after();
                return invoke;
            }
        });
        return shangpin;
    }

}
